/*
 * license-updater - Copyright (c) 2012 MSF. All rights reserved.
 * 
 * This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General
 * Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 */
package br.msf.netbeans.licenseupdater;

import br.msf.commons.netbeans.util.JavaPackage;
import org.netbeans.api.project.Project;
import org.netbeans.api.project.ProjectUtils;
import org.openide.util.NbPreferences;

/**
 * <p>TODO
 *
 * @author Marcius da Silva da Fonseca (sf.marcius@gmail.com)
 * @version 1.0
 * @since license-updater-1.0
 */
public class LicenseUpdaterParams {

    public static final String DEFAULT_LICENSE = "${project.name} - Copyright (c) ${year} ${project.publisher}. All rights reserved.";
    protected Project project;
    protected JavaPackage basePackage;
    protected UpdateMode updateMode = UpdateMode.ALL_FILES;
    protected Integer maxLineLength;
    protected String licenseText;
    protected String projectPublisher;

    public LicenseUpdaterParams() {
        load();
    }

    public int getMaxLineLength() {
        return maxLineLength;
    }

    public void setMaxLineLength(int maxLineLength) {
        this.maxLineLength = maxLineLength;
    }

    public UpdateMode getUpdateMode() {
        return updateMode;
    }

    public void setUpdateMode(UpdateMode updateMode) {
        this.updateMode = updateMode;
    }

    public String getLicenseText() {
        return licenseText;
    }

    public void setLicenseText(String licenseText) {
        this.licenseText = licenseText;
    }

    public Project getProject() {
        return project;
    }

    public void setProject(Project project) {
        this.project = project;
    }

    public String getProjectPublisher() {
        return projectPublisher;
    }

    public void setProjectPublisher(String projectPublisher) {
        this.projectPublisher = projectPublisher;
    }

    public JavaPackage getBasePackage() {
        return basePackage;
    }

    public void setBasePackage(JavaPackage basePackage) {
        this.basePackage = basePackage;
    }

    public final void load() {
        Class c = LicenseUpdaterWizardAction.class;
        this.maxLineLength = Integer.parseInt(NbPreferences.forModule(c).get("maxLineLength", "120"));
        this.projectPublisher = NbPreferences.forModule(c).get("projectPublisher", System.getProperty("user.name"));
        this.licenseText = NbPreferences.forModule(c).get("licenseText", DEFAULT_LICENSE);
    }

    public final void store() {
        Class c = LicenseUpdaterWizardAction.class;
        NbPreferences.forModule(c).put("maxLineLength", Integer.toString(this.maxLineLength));
        NbPreferences.forModule(c).put("projectPublisher", this.projectPublisher);
        NbPreferences.forModule(c).put("licenseText", this.licenseText);
    }

    public String getProjectName() {
        return ProjectUtils.getInformation(project).getDisplayName();
    }

    public enum UpdateMode {

        ALL_FILES,
        WITHOUT_LICENSE_FILES;
    }
}
